﻿using System.Linq.Expressions;
using System.Runtime.CompilerServices;

namespace DynamicLogicExpression.Extensions;

public static class PropertyNavigationExtensions
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Type GetDeepestValueType(this PropertyNavigation propNav)
        => propNav.SubNavigation is null ? propNav.PropertyInfo.PropertyType : propNav.SubNavigation.GetDeepestValueType();

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static MemberExpression GetNestedMemberExpreesion(this MemberExpression member, PropertyNavigation propNav)
        => propNav.SubNavigation is null
                ? member
                : Expression.Property(member, propNav.SubNavigation.Navigation).GetNestedMemberExpreesion(propNav.SubNavigation);
}